package com.ophiux.cs.application.user.impl.recore;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.application.core.Throws.ParamException;
import com.ophiux.cs.application.user.dto.getUserRecoreRequest;
import com.ophiux.cs.application.user.dto.getUserRecoreResponse;
import com.ophiux.cs.domain.user.model.entity.UserLoginRecore;
import com.ophiux.cs.domain.user.repositories.IUserRecoreRepository;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class getUserRecoreService {
	@Autowired
	IUserRecoreRepository iUserRecoreRepository;
	
	public Result<getUserRecoreResponse> getUserRecore(getUserRecoreRequest dto){
		getUserRecoreResponse response = null;
		try {
			
			try {
				/**
				 * 验证参数非空
				 */
				dto.paramVer();
			} catch (ParamException e) {
				return Result.fail(ResultEnum.requestParamFail.getCode(), e.getExceptionMessage());
			}
			
			UserLoginRecore recore= iUserRecoreRepository.getUserRecoreByUserId(dto.getUSER_ID());
			if(recore != null) {
				response = new getUserRecoreResponse();
				response.setLOGIN_TIME(recore.getLOGIN_TIME());
				response.setLOGIN_TOKEN(recore.getLOGIN_TOKEN());
				response.setLOGOUT_TIME(recore.getLOGOUT_TIME());
				response.setPLATFORM_ID(recore.getPLATFORM_ID());
				response.setSTATE(recore.getSTATE());
				response.setUSER_ID(recore.getUSER_ID());
			}
			return Result.success(response);
		} catch (Exception e) {
			log.info("getUserRecore接口异常",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException);
		}
	}
}
